package com.chen.demo.javase.algorithm.leetcode.editor.cn;
//给定一个字符串，你需要反转字符串中每个单词的字符顺序，同时仍保留空格和单词的初始顺序。 
//
// 
//
// 示例： 
//
// 输入："Let's take LeetCode contest"
//输出："s'teL ekat edoCteeL tsetnoc"
// 
//
// 
//
// 提示： 
//
// 
// 在字符串中，每个单词由单个空格分隔，并且字符串中不会有任何额外的空格。 
// 
// Related Topics 字符串 
// 👍 262 👎 0

import com.sun.deploy.util.StringUtils;

public class ReverseWordsInAStringIii {
    public static void main(String[] args) {
        System.out.println(reversWords("Let's take LeetCode contest"));

    }

    public static String reversWords(String s) {
        StringBuilder sb = new StringBuilder();
        String[] strArrays = s.split(" ");
        for (int i = 0; i < strArrays.length; i++) {
            sb.append(reverseStr(strArrays[i]));
            if (i < strArrays.length - 1) {
                sb.append(" ");
            }
        }
        return sb.toString();
    }

    public static String reverseStr(String str) {
        char[] chars = str.toCharArray();
        char temp;
        for (int i = 0; i < chars.length / 2; i++) {
            temp = chars[i];
            chars[i] = chars[chars.length - i - 1];
            chars[chars.length - i - 1] = temp;
        }
        return String.valueOf(chars);
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public String reverseWords(String s) {
            return "";
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}